home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / SCROLL.SWG / 0002_SCROLL2.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  7KB  |  323 lines

  1. Program Scroll;
  2. Uses
  3.   Crt, Dos;
  4. Const
  5.   Null       = #0;
  6.   UpArrow    = #72;
  7.   LeftArrow  = #75;
  8.   RightArrow = #77;
  9.   DownArrow  = #80;
  10.   PageUp     = #73;
  11.   PageDown   = #81;
  12.   ESC        = #27;
  13.  
  14. Type
  15.   StrPtr = ^LineBuffer;
  16.  
  17.   LineBuffer = Record
  18.     Line   : String[255];
  19.     Next   : StrPtr;
  20.     Prev   : StrPtr;
  21.     Up23   : StrPtr;
  22.     Down23 : StrPtr;
  23.   end;
  24. Var
  25.   F       : Text;
  26.   First,
  27.   Last,
  28.   Prev,
  29.   Current : StrPtr;
  30.   Line    : Byte;
  31.   Row     : Byte;
  32.  
  33. Function PadString( S : String ) : String;
  34. Var
  35.   X : Byte;
  36. begin
  37.   if ord(S[0]) > 79 then S[0]:=Chr(80);
  38.   For X := (Length(S) + 1) to 79 Do
  39.     S[X] := ' ';
  40.   S[0] := Chr(79);
  41.   PadString := S;
  42. end;
  43.  
  44. Procedure Normal;
  45. begin
  46.   TextColor(15);
  47.   TextBackGround(0);
  48. end;
  49.  
  50. Procedure HighLite;
  51. begin
  52.   TextColor(10);
  53.   TextBackGround(7);
  54. end;
  55.  
  56. Procedure AddString;
  57. Var
  58.   S : String;
  59.  
  60. begin
  61.   if First = Nil then
  62.   begin
  63.     Line := 1;
  64.     New(Current);
  65.     Current^.Prev   := Nil;
  66.     Current^.Next   := Nil;
  67.     Current^.Up23   := Nil;
  68.     Current^.Down23 := Nil;
  69.     ReadLn(F, S);
  70.     Current^.Line   := S;
  71.     Last  := Current;
  72.     First := Current;
  73.   end
  74.   else
  75.   begin
  76.     Prev := Current;
  77.     New(Current);
  78.     Current^.Prev:=Prev;
  79.     Current^.Next:=Nil;
  80.     ReadLn(F,Current^.Line);
  81.     if Line = 23 then
  82.     begin
  83.       Current^.Up23 := First;
  84.       First^.Down23 := Current;
  85.       Current^.Down23:= Nil;
  86.     end
  87.     else
  88.     begin
  89.       if Line > 23 then
  90.       begin
  91.         Current^.Up23 := Prev^.Up23^.Next;
  92.         Current^.Up23^.Down23 := Current;
  93.         Current^.Down23:=Nil;
  94.       end
  95.       else
  96.       begin
  97.         Current^.Up23:=Nil;
  98.         Current^.Down23:=Nil;
  99.       end;
  100.     end;
  101.     Prev^.Next:=Current;
  102.     Last:=Current;
  103.     if Line<=60 then
  104.       Line:=Line + 1;
  105.   end;
  106. end;
  107.  
  108. Procedure DrawScreen( This : StrPtr);
  109. Var
  110.   TRow : Byte;
  111. begin
  112.   TRow:=1;
  113.   While TRow<=23 Do
  114.    begin
  115.      GotoXY(1,TRow);
  116.      Write(PadString(This^.Line));
  117.      This:=This^.Next;
  118.      TRow:=TRow + 1;
  119.    end;
  120. end;
  121.  
  122. Procedure Scrolling;
  123. Var
  124.   InKey : Char;
  125. begin
  126.   While (MemAvail>272) and (not Eof(F)) Do AddString;
  127.   if not Eof(F) then
  128.    begin
  129.      GotoXY(1,1);
  130.      TextColor(10);
  131.      Write('Entire File not Loaded');
  132.    end;
  133.   Current:=First;
  134.   Window(1,1,1,79);
  135.   ClrScr;
  136.   HighLite;
  137.   GotoXY(1,1);
  138.   Write(PadString(ParamStr(1)));
  139.   Window(2,1,24,80);
  140.   Normal;
  141.   DrawScreen(First);
  142.   Row:=1;
  143.   Window(2,1,25,80);
  144.   While InKey<>#27 Do
  145.   begin
  146.     InKey:=ReadKey;
  147.     Case InKey of
  148.       Null :
  149.       begin
  150.         InKey:=ReadKey;
  151.         Case InKey of
  152.           UpArrow :
  153.           begin
  154.             if Current^.Prev = Nil then
  155.             begin
  156.               Sound(2000);
  157.               Delay(50);
  158.               NoSound;
  159.             end
  160.             else
  161.             begin
  162.               if Row = 1 then
  163.               begin
  164.                 GotoXY(1,1);
  165.                 Normal;
  166.                 Write(PadString(Current^.Line));
  167.                 GotoXY(1,1);
  168.                 InsLine;
  169.                 Current:=Current^.Prev;
  170.                 HighLite;
  171.                 Write(PadString(Current^.Line));
  172.               end
  173.               else
  174.               begin
  175.                 GotoXY(1,Row);
  176.                 Normal;
  177.                 Write(PadString(Current^.Line));
  178.                 Row:=Row - 1;
  179.                 GotoXY(1,Row);
  180.                 HighLite;
  181.                 Current:=Current^.Prev;
  182.                 Write(PadString(Current^.Line));
  183.               end;
  184.             end;
  185.           end;
  186.  
  187.           DownArrow :
  188.           begin
  189.             if Current^.Next = Nil then
  190.             begin
  191.               Sound(2000);
  192.               Delay(50);
  193.               NoSound;
  194.             end
  195.             else
  196.             begin
  197.               if Row = 23 then
  198.               begin
  199.                 GotoXY(1,23);
  200.                 Normal;
  201.                 Write(PadString(Current^.Line));
  202.                 GotoXY(1,1);
  203.                 DelLine;
  204.                 GotoXY(1,23);
  205.                 Current:=Current^.Next;
  206.                 HighLite;
  207.                 Write(PadString(Current^.Line));
  208.               end
  209.               else
  210.               begin
  211.                 GotoXY(1,Row);
  212.                 Normal;
  213.                 Write(PadString(Current^.Line));
  214.                 Row:=Row + 1;
  215.                 GotoXY(1,Row);
  216.                 HighLite;
  217.                 Current:=Current^.Next;
  218.                 Write(PadString(Current^.Line));
  219.               end;
  220.             end;
  221.           end;
  222.  
  223.           PageDown :
  224.            begin
  225.             if (Row = 23) and (Current = Last) then
  226.             begin
  227.               Sound(2000);
  228.               Delay(50);
  229.               NoSound;
  230.             end
  231.             else
  232.             begin
  233.               Normal;
  234.               if Current^.Down23 = Nil then
  235.               begin
  236.                 Current:=Last;
  237.                 DrawScreen(Last^.Up23);
  238.                 Row:=23;
  239.                 GotoXY(1,Row);
  240.                 HighLite;
  241.                 Write(PadString(Current^.Line));
  242.               end
  243.               else
  244.               begin
  245.                 Current:=Current^.Down23^.Next;
  246.                 DrawScreen(Current^.Up23);
  247.                 Row:=23;
  248.                 GotoXY(1,Row);
  249.                 HighLite;
  250.                 Write(PadString(Current^.Line));
  251.               end;
  252.             end;
  253.           end;
  254.  
  255.           PageUp :
  256.           begin
  257.             if (Row = 23) and (Current^.Up23 = Last) then
  258.             begin
  259.               Sound(2000);
  260.               Delay(50);
  261.               NoSound;
  262.             end
  263.             else
  264.             begin
  265.               Normal;
  266.               if Current^.Up23 = Nil then
  267.               begin
  268.                 Current:=First;
  269.                 DrawScreen(First);
  270.                 Row:=1;
  271.                 GotoXY(1,Row);
  272.                 HighLite;
  273.                 Write(PadString(First^.Line));
  274.               end
  275.               else
  276.               begin
  277.                 Current:=Current^.Up23^.Prev;
  278.                 DrawScreen(Current);
  279.                 Row:=1;
  280.                 GotoXY(1,Row);
  281.                 HighLite;
  282.                 Write(PadString(Current^.Line));
  283.               end;
  284.             end;
  285.           end;
  286.         else
  287.         begin
  288.           Sound(2000);
  289.           Delay(50);
  290.           NoSound;
  291.         end;
  292.  
  293.         end;
  294.       end;
  295.  
  296.     else
  297.     begin
  298.       Sound(2000);
  299.       Delay(50);
  300.       NoSound;
  301.     end;
  302.  
  303.     end;
  304.   end;
  305. end;
  306.  
  307. begin
  308.   if ParamCount < 1 then
  309.   begin
  310.     WriteLn('Invalid Number of Parameters!!!');
  311.     Halt(1);
  312.   end;
  313.   Assign(F, Paramstr(1));
  314.   Reset(F);
  315.   Current:=Nil;
  316.   First:=Nil;
  317.   Scrolling;
  318.   GotoXY(1, 23);
  319.   WriteLn;
  320.   WriteLn;
  321. end.
  322.  
  323.